import { createStore } from 'vuex'

export default createStore({
  state: {
    selectedArticles:[],
    selectedUsers:[],
    userInfo:{}
  },
  getters: {
  },
  mutations: {
    addArticle(state,val){
      state.selectedArticles.push(val)
    },
    deleteArticle(state,val){
      let tag = state.selectedArticles.indexOf(val)
      state.selectedArticles.splice(tag,1)
    },
    addUser(state,val){
      state.selectedUsers.push(val)
    },
    deleteUser(state,val){
      let tag = state.selectedUsers.indexOf(val)
      state.selectedUsers.splice(tag,1)
    },
    setUserInfo(state,val){
      state.userInfo = val
    }
  },
  actions: {
    addArticleAction({commit},val){
      commit('addArticle',val)
    },
    deleteArticleAction({commit},val){
      commit('deleteArticle',val)
    },
    addUserAction({commit},val){
      commit('addUser',val)
    },
    deleteUserAction({commit},val){
      commit('deleteUser',val) 
    }
  },
  modules: {
  }
})
